/*
 * @Author: zqx me_zqx@163.com
 * @Date: 2024-06-24 16:32:21
 * @LastEditors: zqx me_zqx@163.com
 * @LastEditTime: 2025-05-15 11:38:37
 * @FilePath: /XMate-h5/src/store/modules/salesTemplate.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from "pinia";
import {
  getGoodsCategoryAPI,
  updateQuestionAPI
} from "@/services/salesTemplate";
import { showLoadingToast, closeToast } from "vant";

export const useSalesTemplateStore = defineStore("interviewStore", {
  state: () => ({
    confId: "",
    templates: undefined,
    goodsQuestions: undefined
  }),

  actions: {
    async getGoodsCategoryAction() {
      if (this.confId?.length === 0) return;
      const data = await getGoodsCategoryAPI(this.confId);
      if (data.templates) {
        this.templates = data.templates;
      }
      if (data.goodsQuestions) {
        this.goodsQuestions = data.goodsQuestions;
      }
      return data;
    },

    setConfId(confId) {
      this.confId = confId;
    },

    async updateQuestionAction(goodsId, parameter) {
      showLoadingToast({
        message: "AI正在全力生成...",
        forbidClick: true,
        duration: 0
      });
      const res = await updateQuestionAPI(goodsId, parameter);
      console.log("updateQuestionAction: ", res);
      closeToast();
      return res;
    }
  }
});
